using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/****************************************************
// 功能：英雄表现控制 技能释放显示、旁白（击杀）
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2025/4/1 10:46:50
*****************************************************/

public class HeroView : MainViewUnit
{
    public Transform sk1;
    public Transform sk2;
    public Transform sk3;
    
    private Hero hero;
    
    public override void Init(LogicUnit logicUnit)
    {
        base.Init(logicUnit);
        
        hero = logicUnit as Hero;
        
        skillRange.gameObject.SetActive(false);
        if (sk1 != null) { sk1.gameObject.SetActive(false); }
        if (sk2 != null) { sk2.gameObject.SetActive(false); }
        if (sk3 != null) { sk3.gameObject.SetActive(false); }
    }

    protected override Vector3 GetUnitViewDir()
    {
        return hero.IsSkillSpelling() ? viewTargetDir :
            // 玩家朝向使用UI输入位置朝向，不使用物理引擎运算修正方向
            hero.InputDir.ConvertViewVector3();
    }

    public void SetSkillGuide(int skillIndex, bool state, ReleaseModeEnum mode, Vector3 vector)
    {
        switch (skillIndex)
        {
            case 1:
                sk1.gameObject.SetActive(state);
                if (state)
                {
                    UpdateSkillGuide(sk1, mode, vector);
                }
                break;
            case 2:
                sk2.gameObject.SetActive(state);
                if (state)
                {
                    UpdateSkillGuide(sk2, mode, vector);
                }
                break;
            case 3:
                sk3.gameObject.SetActive(state);
                if (state)
                {
                    UpdateSkillGuide(sk3, mode, vector);
                }
                break;
        }
    }

    public void DisableSkillGuide(int skillIndex)
    {
        switch (skillIndex)
        {
            case 1:
                if (sk1 != null) { sk1.gameObject.SetActive(false); }
                break;
            case 2:
                if (sk2 != null) { sk2.gameObject.SetActive(false); }
                break;
            case 3:
                if (sk3 != null) { sk3.gameObject.SetActive(false); }
                break;
        }
    }

    private void UpdateSkillGuide(Transform sk, ReleaseModeEnum mode, Vector3 vector)
    {
        if (mode == ReleaseModeEnum.Postion)
        {
            sk.localPosition = vector;
        }
        else
        {
            var angle = Vector2.SignedAngle(new Vector2(vector.x, vector.z), new Vector2(0, 1));
            sk.localEulerAngles = new Vector3(0, angle,0);
        }
    }
}
